package com.brid.careasy;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * @Author: sijunqiang
 * @Date: 2020/5/6 16:27
 * @Description:
 */

@Slf4j
public class SendCarEasy {


    public static String getCarEasyViolation(ViolationDTO violationDTO) {
        //请求参数,按键排序
        Long timespan = System.currentTimeMillis();
        Map<String, String> requestMap = new TreeMap<String, String>(new Comparator<String>() {
            @Override
            public int compare(String str1, String str2) {
                return str1.compareTo(str2);
            }
        });
        requestMap.put("carType", violationDTO.getCarType());
        requestMap.put("carNumber", violationDTO.getCarLicenseNo());
        requestMap.put("carCode", violationDTO.getVinNo());
        requestMap.put("carDriveNumber", violationDTO.getCarEngineNo());
        List<String> list = new ArrayList<>();
        requestMap.entrySet().stream().forEach(x -> list.add(x.getValue()));
        String sorteStr = StringUtils.join(list, "");
        String sign = MD5Utiles.MD5(timespan.toString().concat(sorteStr).concat("6A3BD8C7C7EC905FEFD1B11E93690157"));
        String url = String.format("%s%s?appid=%s&timespan=%s&sign=%s&version=3",
                "http://test.cx580.com:8311",
                "/cxy/vio/query",
                "shxdzntest",
                timespan,
                sign);
        String response = null;
        try {
            response = HttpPost.post("http://test.cx580.com:8311", JSON.toJSONString(requestMap), "application/json;charset=UTF-8", 5000);
            log.info(" [车行易-电子眼违章查询]： 成功消息： 响应成功的违章数据：{}", response);
        } catch (Exception e) {
            log.error("[车行易-电子眼违章查询]：失败消息：响应失败的违章信息:", e);
        }
        return response;
    }



    //car.easy.url=http://test.cx580.com:8311
    //car.easy.appid=shxdzntest
    //car.easy.secrectKey=6A3BD8C7C7EC905FEFD1B11E93690157
    //##回调的是仙豆地址test
//

 //#车行易的基本配置信息 测试环境 8311
 // car.easy.url=http://test.cx580.com:8311
 // car.easy.appid=shxdzntest
 // car.easy.secrectKey=6A3BD8C7C7EC905FEFD1B11E93690157
    /*
     车牌号 号牌类型 车架号 发动机号
     粤A002E2 02 M80498 55B30A
     粤A006DQ 02 094005 D51667
     粤A023SH 02 532410 382726
     以上数据仅供测试，不可外传哦
    *
    *
    * */

    // 点击测试发送
    public static void main(String[] args) {
        ViolationDTO build = ViolationDTO.builder()
                .carEngineNo("55B30A")
                .carLicenseNo("粤A002E2")
                .carType("02")
                .pubCar("0")
                .vinNo("M80498")
                .build();

        String carEasyViolation = getCarEasyViolation(build);
        log.info("响应的数据:[{]", carEasyViolation);
    }







}
